home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / CH2 / Fruit.cs < prev    next >
Text File  |  2006-05-29  |  2KB  |  37 lines

  1. // ========================================================================
  2. //  Fruit.cs
  3. //
  4. //  This program adds up the costs and quantities of selected fruit types
  5. //  and outputs the results to the display
  6. // ========================================================================
  7.  
  8. function runFruit()
  9. // ----------------------------------------------------
  10. //     Entry point for the program.
  11. // ----------------------------------------------------
  12. {
  13.  $bananaCost=1.15;// initilize the value of our variables
  14.  $appleCost=0.55; //   (we don't need to repeat the above
  15.  $numApples=3;    //   comment for each initialization, just
  16.  $numBananas=1;   //   group the init statements together.)
  17.  
  18.  $numFruit=0;     // always a good idea to initialize *all* variables!
  19.  $total=0;        // (even if we know we are going to change them later)
  20.  
  21.  echo("Cost of Bananas(ea.):$"@$bananaCost);
  22.              // the value of $bananaCost gets concatenated to the end
  23.              // of the "Cost of Bananas:" string. Then the
  24.              // full string gets printed. same goes for the next 3 lines
  25.  echo("Cost of Apples(ea.):$"@$appleCost);
  26.  echo("Number of Bananas:"@$numBananas);
  27.  echo("Number of Apples:"@$numApples);
  28.  
  29.  $numFruit=$numBananas+$numApples; // add up the total number of fruits
  30.  $total = ($numBananas * $bananaCost) +
  31.                ($numApples * $appleCost);  // calculate the total cost
  32.              //(notice that statements can extend beyond a single line)
  33.  
  34.  echo("Total amount of Fruit:"@$numFruit); // output the results
  35.  echo("Total Price of Fruit:$"@$total@"0");// add a zero to the end
  36.                               // to make it look better on the screen
  37. }